package com.chj.design.sk;

public class Code11_Decorator3 {

	// 抽象构件角色“齐天大圣”接口定义了一个move()方法
	// 大圣的尊号
	public interface TheGreatestSage {

		public void move();
	}

	// 具体构件角色“大圣本尊”猢狲类
	public static class Monkey implements TheGreatestSage {

		@Override
		public void move() {
			// 代码
			System.out.println("Monkey Move");
		}

	}

	// 抽象装饰角色“七十二变”
	public static abstract class Change implements TheGreatestSage {
		private TheGreatestSage sage;

		public Change(TheGreatestSage sage) {
			this.sage = sage;
		}

		@Override
		public void move() {
			// 代码
			sage.move();
		}
	}

	// 具体装饰角色“鱼儿”
	public static class Fish extends Change {

		private TheGreatestSage sage;

		public Fish(TheGreatestSage sage) {
			super(sage);
			this.sage = sage;
		}

		@Override
		public void move() {
			sage.move();
			// 代码
			System.out.println("Fish Move");
		}
	}

	// 具体装饰角色“鸟儿”
	public static class Bird extends Change {
		private TheGreatestSage sage;

		public Bird(TheGreatestSage sage) {
			super(sage);
			this.sage = sage;
		}

		@Override
		public void move() {
			sage.move();
			// 代码
			System.out.println("Bird Move");
		}
	}

	public static void main(String[] args) {
		TheGreatestSage sage = new Monkey();
		// 第一种写法
		TheGreatestSage bird = new Bird(sage);
		TheGreatestSage fish = new Fish(bird);
		// 第二种写法
		// TheGreatestSage fish = new Fish(new Bird(sage));
		fish.move();
	}

}
